package com.game.level;

import java.util.ArrayList;

import map.Map;
import object.obj2D.bullet.IBullet;
import object.obj2D.bullet.MGunBullet;
import object.obj3D.enemy.Character;
import object.obj3D.enemy.Player;
import object.obj3D.enemy.Protoss;
import object.obj3D.enemy.Teminator;
import system.Device;
import terrain.BruteForce_Terrain;
import MD2Model.Vector3;

import com.game.GamePlay;
import com.game.R;
import com.game.HUD.GUIGame;
import com.game.state.Loading;

public class Mission1 extends Mission {

	static int m_iMaxProtoss = 40;
	static int m_iMaxTerminator = 2;
	
//	Loading loading;
	
	public Mission1(){
		// init player
		//Loading.SetNumberPart(3);
//		loading = new Loading(4);
		Loading.SetNumberPart(6);
	}
	
	@Override
	public void Init() {
		// init enemy
		
	}

	@Override
	public void Destroy() {
		// TODO Auto-generated method stub
		this.m_player = null;
	}

	@Override
	public void ProcessKeyboard(GamePlay gamePlay) {
		// TODO Auto-generated method stub
		
		super.ProcessKeyboard(gamePlay);
	}

	@Override
	public void LoadResource() {
		// TODO Auto-generated method stub
		if (m_bReadyResources)
			return;
		switch (m_resourceID) {
		case 0:
			InitEnemyValue();
			MGunBullet.Init();
			break;
		case 1:
			GUIGame.SetMission(this);
			break;
		case 2:
			InitModel();
			break;
		case 3:
			InitPlayer();
			break;
		case 4:
			
			try{
			this.m_charList.add(new Teminator(new Vector3(0, 0, -12)));
			}catch(Exception e)
			{
				System.out.println("error " + e.getMessage());
			}
			break;
		case 5:
			InitTerrain();
			break;
		default:
			m_bReadyResources = true;
		}
		m_resourceID++;
		Loading.UpdateProgess();
	}
	
	public void InitEnemyValue(){
		m_charList = new ArrayList<Character>();
		m_enemyBullet = new ArrayList<IBullet>();
		m_playerBullet = new ArrayList<IBullet>();
		this.setMaxPlayerHP(1000);
		this.setMaxProtossHP(100);
		this.setMaxTerminatorHP(500);
		m_totalEnemyHP = getMaxProtossHP()*m_iMaxProtoss + getMaxTerminatorHP()*m_iMaxTerminator;
	}
	
	public void InitModel(){
		Protoss.Initialize();
		Teminator.Initialize();
	}
	
	public void InitPlayer(){
		this.m_player = new Player();
		m_player.SetCurrentHP(getMaxPlayerHP());
		m_player.AddFireBullet(40);
		m_player.AddMachineBullet(99999);
		m_player.AddMissile(10);
	}
	
	private void InitTerrain(){
		terrain = new BruteForce_Terrain();
		terrain.LoadHeightMapFromRawFile(Device.GetContext().getResources().openRawResource(R.drawable.height128), 128, 128);
//		terrain.LoadHeightMapFromRawFile(Device.GetContext().getResources().openRawResource(R.drawable.terrain32x32), 32, 32);
		terrain.SetTexture(getClass().getResourceAsStream("/res/drawable-hdpi/ground.png"));
//		terrain.LoadHeightMapFromBitmap(Device.GetContext().getResources().openRawResource(R.drawable.terrain_png64x64));
		terrain.SetTexture(Device.GetContext().getResources().openRawResource(R.drawable.ground));
		Map.SetTerrain(terrain);
	}

}
